package com.brain.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.widget.ImageView;

public class LoadActivity extends Activity {
	private int imageIndex = 0;
	private int stop = 0;
	private Handler mHandler = new Handler();
	private ImageView imgLoading;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.loading);
		imgLoading = (ImageView) findViewById(R.id.dialog_load_img);
		mHandler.removeCallbacks(mUpdateTimeTask);
		mHandler.postDelayed(mUpdateTimeTask, 100);
		
		stop = 1;
	      Intent intent =  new Intent(LoadActivity.this, MainActivity.class);
		  intent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
	      startActivity(intent);
	      
	      finish();

   }
    
    
	private Runnable mUpdateTimeTask = new Runnable() 
	{   
		@Override
		public void run() 
		{   
  		  rotateImg(imageIndex ++);
		  if(imageIndex == 5)
			  imageIndex = 0;
		      
			if(stop == 1)
			{
				mHandler.sendEmptyMessage(0);
			}
			else
			{
				mHandler.postDelayed(mUpdateTimeTask, 100);
			}
		}
	};
    
	private void rotateImg(int i)
	{	        
		imgLoading.setBackgroundResource(R.drawable.loading_1 + i);
	}
}
